import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 模板
const Default = () => import('../layouts/Default.vue')

const Home = () => import('../views/home/index.vue')
const Search = () => import('../views/home/Search.vue')
const Info = () => import('../views/infoOpen/Info.vue')
const About = () => import('../views/aboutCompany/About.vue')
const Law = () => import('../views/regulations/Law.vue')
const Vip = () => import('../views/memberServe/Vip.vue')
const Profiles = () => import('../views/profiles/Profiles.vue')
const PropsTradeIndex = () => import('../views/propsTrade/index.vue')
const PropsTrade = () => import('../views/propsTrade/PropsTrade.vue')
const PropsTradeInfo = () => import('../views/propsTrade/TradeInfo.vue')
const TradeEnroll = () => import('../views/propsTrade/TradeEnroll.vue')
const Login = () => import('../page/login/Login.vue')
const Register = () => import('../page/register/Regis.vue')



const Err404 = () => import('../page/error/404.vue')

const routes = [
  {
    path: '/', name: 'Default', component: Default, redirect: '/index',
    children: [
      { path: 'index', name: 'index', component: Home },
      { path: 'search', name: 'search', component: Search },
      {
        path: 'propsTrade', name: 'propsTrade', component: PropsTradeIndex,
        children: [
          { path: '', name: 'propsTrade', component: PropsTrade },
          { path: 'tradeinfo', name: 'propsTrade', component: PropsTradeInfo },
          { path: 'tradeenroll', name: 'propsTrade', component: TradeEnroll },
        ]
      },
      { path: 'info', name: 'info', component: Info },
      { path: 'vip', name: 'vip', component: Vip },
      { path: 'law', name: 'law', component: Law },
      { path: 'about', name: 'about', component: About },
      { path: 'profiles', name: 'profiles', component: Profiles },

      { path: "login", name: "login", component: Login, },
      { path: "register", name: "register", component: Register, },
    ]
  },
  { path: '*', name: 'err404', component: Err404 }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
